/**
 * Provider 状态管理demo
 * 
 * 参考：
 * https://juejin.im/post/5d00a84fe51d455a2f22023f
 */
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_demo_list/application.dart';
import 'package:provider/provider.dart';
import '../provider/counter_provider.dart';
import './provider_demo_second_page.dart';

class ProviderDemoPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final _counter = Provider.of<CounterProvider>(context);
    final _textSize = Provider.of<int>(context).toDouble();
    return WillPopScope(
      onWillPop: () {
        /// 退出时，清理count
        _counter.clearCount();
        Application.router.pop(context);
      },
      child: Scaffold(
        appBar: AppBar(
          title: Text("ProviderDemoPage"),
        ),
        body: Center(
          child: Text(
            "Value:${_counter.value}",
            style: TextStyle(fontSize: _textSize),
          ),
        ),
        floatingActionButton: FloatingActionButton(
          child: Icon(Icons.navigate_next),
          onPressed: () => Navigator.of(context).push(CupertinoPageRoute(
              builder: (context) => ProviderDemoSecondPage())),
        ),
      ),
    );
  }
}
